

cap program drop DeleteSingletons
program define DeleteSingletons
syntax

noi di in yellow _n "Delete singleton employers"

preserve

	contract empid trt
	qui gen ones=1
	qui bysort empid: egen ttl=total(ones)
	
	qui gen singleton=0
	qui replace singleton=1 if ttl==1
	tab singleton [fw=_freq], m
	
	qui drop if singleton==1
	
	* Dedup
	keep empid
	contract empid
	keep empid
	
	* Save
	qui CheckMiss
	qui ChkSrt empid
	tempfile tmp
	qui save `tmp'
	
restore

sort empid
merge m:1 empid using `tmp'
macro drop _tmp
noi di in yellow _n "Deleting singleton employers: " _cont
keep if _merge==3
drop _merge

	
end

